package com.car.carsharing.service.impl;

import com.car.carsharing.mapper.UserMapper;
import com.car.carsharing.pojo.User;
import com.car.carsharing.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(String username, String password) {
        User user  = new User().getUser(username,password);
        return userMapper.getUser(user);
    }

    @Override
    public Integer regist(String username, String password) {
        User user  = new User();
        user.setUsername(username);

        User mapperUser = userMapper.getUser(user);
        if(mapperUser != null){
            return -1;
        }
        user.setPassword(password);
         userMapper.regist(user);
        return user.getId();
    }
}
